﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Compilation;
using System.Globalization;

namespace CodeArt.SharePoint.MultiLanSupport
{
    public class SPResourceExpressionBuilder : Microsoft.SharePoint.SPResourceExpressionBuilder
    {
        public override object EvaluateExpression(object target, System.Web.UI.BoundPropertyEntry entry, object parsedData, System.Web.Compilation.ExpressionBuilderContext context)
        {
            //return parsedData ;

            if (entry.PropertyInfo != null)
            {
                return base.EvaluateExpression(target, entry, parsedData, context);
            }
            ResourceExpressionFields fields = parsedData as ResourceExpressionFields;
            if (fields == null)
            {
                return null;
            }

            

            CultureInfo cf = System.Threading.Thread.CurrentThread.CurrentUICulture;

            cf = new CultureInfo(UICultureManager.English_Lan_Name);

            if (!string.IsNullOrEmpty(fields.ClassKey))
            {
                return HttpContext.GetGlobalResourceObject(fields.ClassKey, fields.ResourceKey, cf);
            }
            return HttpContext.GetLocalResourceObject(context.VirtualPath, fields.ResourceKey, cf);

        }
    }
}
